﻿using System.Collections.Generic;
using System.Linq;

namespace SharePhone.Common.List
{
    public class FieldInfo
    {
        public string ID
        {
            get
            {
                if (Properties == null)
                    return null;
                return Properties.Where(f => f.Name == "ID").First().Value;
            }
        }

        public string InternalName
        {
            get { return Properties == null ? null : Properties.Where(f => f.Name == "Name").First().Value; }
        }

        public string DisplayName
        {
            get { return Properties == null ? null : Properties.Where(f => f.Name == "DisplayName").First().Value; }
        }

        public string FieldType
        {
            get { return Properties == null ? null : Properties.Where(f => f.Name == "Type").First().Value; }
        }

        /// <summary>
        /// Returns the GUID of the lookup list if this is a lookup field, otherwise null.
        /// </summary>
        public string List
        {
            get { return FieldType == "Lookup" ? Properties.Where(f => f.Name == "List").First().Value : null; }
        }

        public List<FieldProperty> Properties { get; set; }
    }
}